﻿using EFCore.BulkExtensions;
using Furion;
using Furion.DatabaseAccessor;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.UnifyResult;
using JoyAdmin.Core;
using Mapster;
using Mapster.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using Serilog;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using TencentCloud.Ame.V20190916.Models;
using TulingMember.Application.Dto;
using TulingMember.Application.Helper;
using TulingMember.Application.Util;
using TulingMember.Application.ViewModel;
using TulingMember.Core;
using Yitter.IdGenerator;

namespace TulingMember.Application
{
    [ApiDescriptionSettings("处方单")]
    public class SaleOrderService : IDynamicApiController
    {
        private readonly ILogger _logger;
        private readonly IRepository<cts_Customer> _customerRepository;
        private readonly IRepository<cts_CustomerPayLog> _customerpaylogRepository;
        private readonly IRepository<cts_SaleOrder> _saleorderRepository;
        private readonly IRepository<cts_SaleOrderDetail> _saleorderdetailRepository;
        private readonly IRepository<cts_PrintTag> _printtagRepository;
        private readonly IRepository<cts_Product> _productRepository;
        private readonly IRepository<cts_ProductLog> _productlogRepository;
        private readonly IRepository<User> _userRepository;
        public SaleOrderService(ILogger logger
            , IRepository<cts_Customer> customerRepository
            , IRepository<cts_CustomerPayLog> customerpaylogRepository
            , IRepository<cts_SaleOrder> saleorderRepository
            , IRepository<cts_SaleOrderDetail> saleorderdetailRepository
            , IRepository<cts_PrintTag> printtagRepository
            , IRepository<cts_Product> productRepository
            , IRepository<cts_ProductLog> productlogRepository
            , IRepository<User> userRepository)
        {
            _logger = logger;
            _customerRepository = customerRepository;
            _customerpaylogRepository = customerpaylogRepository;
            _saleorderRepository = saleorderRepository;
            _saleorderdetailRepository = saleorderdetailRepository;
            _printtagRepository = printtagRepository;
            _productRepository = productRepository;
            _productlogRepository = productlogRepository;
            _userRepository = userRepository;
        }
        private static int Balance = App.GetConfig<int>("Common:Balance");
        //private static int VerificationAmount = Convert.ToInt32(App.Configuration["Common:VerificationAmount"].ToString());
        #region 处方单
        /// <summary>
        /// 获取客户处方记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public PagedList<cts_SaleOrder> SearchCustomerSaleOrders(BaseInput input)
        {
            var search = _saleorderRepository.Where(m => m.CustomerId == input.customerid).AsQueryable();
            if (input.sdate != null)
            {
                search = search.Where(m => m.OrderDate >= input.sdate);
            }
            if (input.edate != null)
            {
                var edate = input.edate?.AddDays(1).Date;
                search = search.Where(m => m.OrderDate < edate);
            }
            search = search.OrderByDescending(m => m.OrderDate);
            return search.ToPagedList(input.page, input.size);
        }

        /// <summary>
        /// 获取药品处方单明细记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public PagedList<SaleOrderDetailExport> SearchSaleOrderDetail(BaseInput input)
        {
            var search = _saleorderdetailRepository.Include(x => x.Product).Where(m => m.ProductId == input.productid).AsQueryable();
            search = search.OrderByDescending(m => m.CreatedTime);
            var data = search.ToPagedList(input.page, input.size);
            var result = new PagedList<SaleOrderDetailExport>
            {
                PageIndex = data.PageIndex,
                PageSize = data.PageSize,
                TotalCount = data.TotalCount,
                TotalPages = data.TotalPages,
                HasNextPages = data.HasNextPages,
                HasPrevPages = data.HasPrevPages
            };
            result.Items = data.Items.Select(s => new SaleOrderDetailExport
            {
                ProductName = s.ProductName,
                Manufacturer = s.Product.Manufacturer,
                ManufacturingDate = s.Product.ManufacturingDate,
                ExpirationDate = s.Product.ExpirationDate,
                Price = s.Price,
                Num = s.Num,
                CreatedTime = s.CreatedTime,
            });
            return result;
        }

        /// <summary>
        /// 处方单列表
        /// </summary> 
        public PagedList<SaleOrderQueryViewModel> SearchSaleOrder(BaseInput input)
        {
            var search = _saleorderRepository.Include(s => s.Customer).ThenInclude(m => m.Department)
                .Where(x => !x.Customer.IsDeleted)
                .AsQueryable();

            if (!string.IsNullOrEmpty(input.keyword))
            {
                search = search.Where(m => m.Customer.MedicalCardNo.Contains(input.keyword)
                 || m.OrderDesc.Contains(input.keyword));
            }
            if (input.sdate != null)
            {
                search = search.Where(m => m.CreatedTime >= input.sdate);
            }
            if (input.edate != null)
            {
                var edate = input.edate?.AddDays(1).Date;
                search = search.Where(m => m.CreatedTime < edate);
            }
            if (input.customerid > 0)
            {
                search = search.Where(m => m.CustomerId == input.customerid);
            }
            //type>0审批处方单列表
            if (input.type > 0)
            {
                search = search.Where(m => m.Status != 0 && m.Status != 3);
            }
            var amount = search.GroupBy(m => 1).Select(m => new
            {
                Amount = m.Sum(m => m.Amount),
                FreightFee = m.Sum(m => m.FreightFee),
                EditionFee = m.Sum(m => m.EditionFee),
                GiveupFee = m.Sum(m => m.GiveupFee),
                AllFee = m.Sum(m => m.AllFee)
            }).FirstOrDefault();

            search = search.OrderByDescending(m => m.OrderDate);

            var data = search.ToPagedList(input.page, input.size);

            var result = new PagedList<SaleOrderQueryViewModel>
            {
                PageIndex = data.PageIndex,
                PageSize = data.PageSize,
                TotalCount = data.TotalCount,
                TotalPages = data.TotalPages,
                HasNextPages = data.HasNextPages,
                HasPrevPages = data.HasPrevPages
            };
            result.Items = data.Items.Select(s => new SaleOrderQueryViewModel
            {
                Id = s.Id,
                OrderDate = s.OrderDate,
                OrderNo = s.OrderNo,
                OrderDesc = s.OrderDesc,
                Num = s.Num,
                Weight = s.Weight,
                Amount = s.Amount,
                FreightFee = s.FreightFee,
                EditionFee = s.EditionFee,
                GiveupFee = s.GiveupFee,
                AllFee = s.AllFee,
                PayFee = s.PayFee,
                CustomerBalance = s.CustomerBalance,
                Remark = s.Remark,
                Status = s.Status,
                PrintNum = s.PrintNum,
                Symptom = s.Symptom,
                CustomerName = DisPlayNameHelper.GetDisplayName(s.Customer.Name),
                DepartmentName = s.Customer.Department.Name,
                MedicalCardNo = s.Customer.MedicalCardNo,
                Sex = s.Customer.Sex == Gender.Male ? "男" : "女",
                Birthday = s.Customer.Birthday,
                CustomerAge = s.CustomerAge
            });

            UnifyContext.Fill(amount);
            return result;
        }

        /// <summary>
        /// 获取处方单
        /// </summary> 
        public SaleOrderDto GetSaleOrder(long id)
        {
            var order = _saleorderRepository.Include(s => s.Customer).FirstOrDefault(s => s.Id == id);
            var detail = _saleorderdetailRepository.Include(s => s.Product).Where(m => m.SaleOrderId == id).ToList();
            var printtag = _printtagRepository.Where(m => m.IsShow == 1).ToList();
            return new SaleOrderDto
            {
                printtag = printtag,
                order = order,
                detail = detail,
                displayName = DisPlayNameHelper.GetDisplayName(order.Customer.Name),
                CustomerAge = order.CustomerAge,
                medicalCardNo = order.Customer?.MedicalCardNo,
            };
        }
        /// <summary>
        /// 获取处方单打印
        /// </summary> 

        public SaleOrderDto GetSaleOrderAndPrint(long id)
        {
            var order = _saleorderRepository.Include(s => s.Customer).ThenInclude(m => m.Department).Where(x => x.Id == id).FirstOrDefault();
            //var order = _saleorderRepository.FindOrDefault(id);
            var detail = _saleorderdetailRepository.Where(m => m.SaleOrderId == id).ToList();
            var printtag = _printtagRepository.Where(m => m.IsShow == 1).ToList();
            //获取系统配置
            var tenantid = App.User.FindFirst(ClaimConst.TENANT_ID).Value;
            cts_SystemConfig systemconfig = new cts_SystemConfig();
            var configKey = AppStr.SystemConfig + "_" + tenantid;
            var systemconfigStr = RedisHelper.GetString(configKey);
            if (!string.IsNullOrEmpty(systemconfigStr))
            {
                systemconfig = systemconfigStr.FromJson<cts_SystemConfig>();
            }
            order.PrintNum += 1;
            return new SaleOrderDto
            {
                companyname = systemconfig.configstr1,
                printtag = printtag,
                order = order,
                detail = detail,
                displayName = DisPlayNameHelper.GetDisplayName(order.Customer.Name),
                CustomerAge = order.CustomerAge,
                createName = _userRepository.FindOrDefault(order.CreatedUserId)?.Name,
                reviewerName = order.Status == 1 ? _userRepository.FindOrDefault(order.UpdatedUserId)?.Name : string.Empty
            };
        }
        /// <summary>
        /// 保存处方单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [SecurityDefine("saleorder")]
        [UnitOfWork]
        public async Task<long> SaveSaleOrder(SaleOrderDto dto)
        {
            var order = dto.order;
            var detail = dto.detail;
            if (detail.GroupBy(g => g.ProductId).Where(s => s.Count() > 1).Count() > 0)
            {
                throw Oops.Bah("药品重复，请检查").StatusCode(ErrorStatus.ValidationFaild);
            }
            var Amount = detail.Sum(m => Math.Round(m.Price * m.Num, 2, MidpointRounding.AwayFromZero));
            if (Amount > Balance + 1)
            {
                throw Oops.Bah($"药品总金额,不能大于：{(Balance + 1)}元").StatusCode(ErrorStatus.ValidationFaild);
            }
            var customer = _customerRepository.Where(x => x.Id == order.CustomerId).FirstOrDefault();
            if (customer == null)
                throw Oops.Bah("人员无效，请检查").StatusCode(ErrorStatus.ValidationFaild);
            if (customer != null && Amount > (customer.Balance + 1))
            {
                throw Oops.Bah("余额不足，请检查").StatusCode(ErrorStatus.ValidationFaild);
            }
            var searchsaleorder = _saleorderRepository.Where(x => x.Status != 1 && x.CustomerId == order.CustomerId && x.Id != order.Id).AsQueryable();
            if (searchsaleorder.Count() > 0)
            {
                throw Oops.Bah("当前人员存在未审批的处方单，请检查").StatusCode(ErrorStatus.ValidationFaild);
            }
            var today = DateTime.Now.ToString("yyMMdd");
            var tenantid = App.User.FindFirst(ClaimConst.TENANT_ID).Value;

            //获取系统配置
            cts_SystemConfig systemconfig = new cts_SystemConfig();
            var configKey = AppStr.SystemConfig + "_" + tenantid;
            var systemconfigStr = RedisHelper.GetString(configKey);
            if (!string.IsNullOrEmpty(systemconfigStr))
            {
                systemconfig = systemconfigStr.FromJson<cts_SystemConfig>();
            }

            order.Num = detail.Sum(m => m.Num);
            order.Weight = Math.Round(detail.Sum(m => Math.Round(m.Weight, 2, MidpointRounding.AwayFromZero)), 2, MidpointRounding.AwayFromZero);
            if (systemconfig.config4 == 1)//保留整数
            {
                order.Amount = detail.Sum(m => Math.Floor(m.Price * m.Num));
                order.AllFee = Math.Floor(order.Amount + order.FreightFee + order.EditionFee - order.GiveupFee);

            }
            else
            {
                order.Amount = Math.Round(detail.Sum(m => Math.Round(m.Price * m.Num, 2, MidpointRounding.AwayFromZero)), 2, MidpointRounding.AwayFromZero);
                order.AllFee = Math.Round(order.Amount + order.FreightFee + order.EditionFee - order.GiveupFee, 2, MidpointRounding.AwayFromZero);

            }
            order.OrderDesc = string.Join(';', detail.Select(m => m.ProductName));

            if (order.Id == 0)
            {
                var redisKey = AppStr.SaleOrderNoKey + "_" + tenantid + "_" + today;
                var OrderNoIndex = RedisHelper.StringIncrement(redisKey);
                if (OrderNoIndex == 0)
                {
                    OrderNoIndex = RedisHelper.StringIncrement(redisKey);
                }
                order.Id = YitIdHelper.NextId();
                order.OrderNo = "CF" + today + OrderNoIndex.ToString().PadLeft(3, '0');
                order.Status = dto.status;
                List<cts_SaleOrderDetail> orderDetails = new List<cts_SaleOrderDetail>();
                foreach (var item in detail)
                {
                    var product = _productRepository.Entities.AsNoTracking().Where(s => s.Id == item.ProductId).FirstOrDefault() ?? throw Oops.Bah("药品不存在，请检查").StatusCode(ErrorStatus.ValidationFaild);
                    item.Product = product;
                    _productRepository.ChangeEntityState(item.Product, EntityState.Unchanged);
                    var productName = item.ProductName.Trim();
                    item.ProductId = product.Id;
                    item.SaleOrderId = order.Id;
                    item.Id = YitIdHelper.NextId();

                    if (systemconfig.config4 == 1)//保留整数
                    {
                        item.Amount = Math.Floor(item.Price * item.Num);
                    }
                    else
                    {
                        item.Amount = Math.Round(item.Price * item.Num, 2, MidpointRounding.AwayFromZero);
                    }
                    orderDetails.Add(item);
                }
                await _saleorderRepository.InsertAsync(order);
                await _saleorderdetailRepository.InsertAsync(orderDetails);
            }
            else
            {

                var oldOrder = _saleorderRepository.DetachedEntities.Where(m => m.Id == order.Id).FirstOrDefault();
                if (oldOrder.Status == 1)
                {
                    throw Oops.Bah("已审核处方单不允许修改").StatusCode(ErrorStatus.ValidationFaild);
                }
                order.Status = dto.status;
                await _saleorderRepository.UpdateExcludeAsync(order, new string[] { nameof(order.PrintNum) });
                _saleorderdetailRepository.Where(a => a.SaleOrderId == order.Id).BatchDelete();
                List<cts_SaleOrderDetail> orderDetails = new List<cts_SaleOrderDetail>();
                foreach (var item in detail)
                {
                    var product = _productRepository.Entities.AsNoTracking().Where(s => s.Id == item.ProductId).FirstOrDefault() ?? throw Oops.Bah("药品不存在，请检查").StatusCode(ErrorStatus.ValidationFaild);
                    item.Product = product;
                    _productRepository.ChangeEntityState(item.Product, EntityState.Unchanged);
                    var productName = item.ProductName.Trim();
                    item.SaleOrderId = order.Id;
                    item.Id = YitIdHelper.NextId();
                    if (systemconfig.config4 == 1)//保留整数
                    {
                        item.Amount = Math.Floor(item.Price * item.Num);
                    }
                    else
                    {
                        item.Amount = Math.Round(item.Price * item.Num, 2, MidpointRounding.AwayFromZero);
                    }
                    orderDetails.Add(item);
                }
                await _saleorderdetailRepository.InsertAsync(orderDetails);
            }
            return order.Id;

        }
        /// <summary>
        /// 删除 
        /// </summary>  
        [SecurityDefine("saleorder")]
        public void DeleteSaleOrder(long id)
        {

            var oldOrder = _saleorderRepository.DetachedEntities.Where(m => m.Id == id).FirstOrDefault();
            if (oldOrder.Status == 1 || oldOrder.Status == 2)
            {
                throw Oops.Bah("已审核和待审核处方单不允许删除").StatusCode(ErrorStatus.ValidationFaild);
            }
            _saleorderRepository.FakeDelete(id);
        }
        /// <summary>
        /// 1已审核、0暂存 、2待审核、3已退回
        /// </summary>  
        [SecurityDefine("saleorder")]
        [UnitOfWork]
        public void CheckSaleOrder(CheckDto input)
        {
            var order = _saleorderRepository.FindOrDefault(input.Id);
            if (order.Status == input.Status)
            {
                throw Oops.Bah("该单据无需此操作").StatusCode(ErrorStatus.ValidationFaild);
            }
            var orderDetails = _saleorderdetailRepository.Where(m => m.SaleOrderId == order.Id).ToList();
            foreach (var item in orderDetails)
            {
                var product = _productRepository.FindOrDefault(item.ProductId);
                if (product == null)
                {
                    throw Oops.Bah("药品无效，请退回检查").StatusCode(ErrorStatus.ValidationFaild);
                }
                else
                {
                    if (item.Num > product.Num)
                    {
                        throw Oops.Bah($"药品：{product.Name}库存不足，请退回检查").StatusCode(ErrorStatus.ValidationFaild);
                    }
                }
            }
            order.Status = input.Status;
            var changeAmount = Math.Round(order.PayFee - order.AllFee, 2, MidpointRounding.AwayFromZero);
            if (input.Status == 1)//审核
            {
                //1.变更客户金额
                var customer = _customerRepository.FindOrDefault(order.CustomerId);
                _customerpaylogRepository.Insert(
                    new cts_CustomerPayLog
                    {
                        CustomerId = customer.Id,
                        CustomerName = customer.Name,
                        OrderType = OrderType.Out,
                        OrderId = order.Id,
                        OrderNo = order.OrderNo,
                        OldAmount = customer.Balance,
                        ChangeAmount = changeAmount,
                        NewAmount = customer.Balance + changeAmount,
                        OrderDate = order.OrderDate,
                        Remark = $"【处方单】费用：{order.AllFee}元,付款：{order.Amount}元",
                    });
                customer.Balance += changeAmount;
                //3.库存数量变更
                foreach (var item in orderDetails)
                {
                    var product = _productRepository.FindOrDefault(item.ProductId);

                    _productlogRepository.Insert(new cts_ProductLog
                    {
                        Id = YitIdHelper.NextId(),
                        ProductId = product.Id,
                        ProductName = product.Name,
                        OldNum = product.Num,
                        ChangeNum = -item.Num,
                        NewNum = product.Num - item.Num,
                        TagName = "处方出库",
                        TagType = ProductChangeTag.Out,
                        RelationId = order.Id,
                    });
                    product.Num -= item.Num;
                }

            }
            //else if (input.Status == 0)
            //{ //弃审
            //  //1.变更客户金额
            //    var customer = _customerRepository.FindOrDefault(order.CustomerId);
            //    _customerpaylogRepository.Insert(
            //        new cts_CustomerPayLog
            //        {
            //            CustomerId = customer.Id,
            //            CustomerName = customer.Name,
            //            OrderType = OrderType.Out,
            //            OrderId = order.Id,
            //            OrderNo = order.OrderNo,
            //            OldAmount = customer.Balance,
            //            ChangeAmount = -changeAmount,
            //            NewAmount = customer.Balance - changeAmount,
            //            OrderDate = order.OrderDate,
            //            Remark = "处方单弃审",
            //        });
            //    customer.Balance -= changeAmount;
            //    //3.库存数量变更
            //    foreach (var item in orderDetails)
            //    {
            //        var product = _productRepository.FindOrDefault(item.ProductId);

            //        _productlogRepository.Insert(new cts_ProductLog
            //        {
            //            Id = YitIdHelper.NextId(),
            //            ProductId = product.Id,
            //            ProductName = product.Name,
            //            OldNum = product.Num,
            //            ChangeNum = item.Num,
            //            NewNum = product.Num + item.Num,
            //            TagName = "处方出库弃审",
            //            TagType = ProductChangeTag.In,
            //            RelationId = order.Id,
            //        });
            //        product.Num += item.Num;
            //    }
            //}
            else
            {
                order.Status = input.Status;
            }
        }
        #endregion
        #region 导出
        /// <summary>
        /// 导出处方单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ExportSaleOrder([FromQuery] BaseInput input)
        {
            List<SaleOrderExport> data = this.GetSerchSaleOrderExport(input);
            var fileStream = ExcelHelper.ParseListToExcel(data);
            var fileName = HttpUtility.UrlEncode("处方单_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx", Encoding.GetEncoding("UTF-8"));
            return await Task.FromResult(
             new FileContentResult(fileStream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
             {
                 FileDownloadName = fileName
             });
        }
        /// <summary>
        /// 查询处方单信息-导出
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private List<SaleOrderExport> GetSerchSaleOrderExport(BaseInput input)
        {
            List<SaleOrderExport> SaleOrderExport = new List<SaleOrderExport>();
            var search = _saleorderRepository.Include(s => s.Customer).ThenInclude(m => m.Department).AsQueryable();
            if (!string.IsNullOrEmpty(input.keyword))
            {
                search = search.Where(m => m.Customer.MedicalCardNo.Contains(input.keyword)
                 || m.OrderDesc.Contains(input.keyword));
            }
            if (input.sdate != null)
            {
                search = search.Where(m => m.CreatedTime >= input.sdate);
            }
            if (input.edate != null)
            {
                var edate = input.edate?.AddDays(1).Date;
                search = search.Where(m => m.CreatedTime < edate);
            }
            if (input.customerid > 0)
            {
                search = search.Where(m => m.CustomerId == input.customerid);
            }
            //type>0审批处方单列表
            if (input.type > 0)
            {
                search = search.Where(m => m.Status != 0 && m.Status != 3);
            }
            search = search.OrderByDescending(m => m.OrderDate);
            SaleOrderExport = search.Select(s => new SaleOrderExport
            {
                OrderDate = s.OrderDate,
                OrderNo = s.OrderNo,
                OrderDesc = s.OrderDesc,
                Amount = s.Amount,
                Remark = s.Remark,
                Symptom = s.Symptom,
                CustomerName = DisPlayNameHelper.GetDisplayName(s.Customer.Name),
                DepartmentName = s.Customer.Department.Name,
                Sex = DescriptionExtension.GetEnumDescription(s.Customer.Sex),
                Age = s.CustomerAge
            }).ToList();
            return SaleOrderExport;
        }


        /// <summary>
        /// 导出处方单明细
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ExportSaleOrderDetail([FromQuery] BaseInput input)
        {
            List<SaleOrderDetailExport> data = this.GetSaleOrderDetailExport(input);
            var fileStream = ExcelHelper.ParseListToExcel(data);
            var fileName = HttpUtility.UrlEncode("处方单明细_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx", Encoding.GetEncoding("UTF-8"));
            return await Task.FromResult(
             new FileContentResult(fileStream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
             {
                 FileDownloadName = fileName
             });
        }
        /// <summary>
        /// 获取药品处方单明细记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private List<SaleOrderDetailExport> GetSaleOrderDetailExport(BaseInput input)
        {
            List<SaleOrderDetailExport> SaleOrderDetailExport = new List<SaleOrderDetailExport>();
            var search = _saleorderdetailRepository.Include(x => x.Product).Where(m => m.ProductId == input.productid).AsQueryable();
            search = search.OrderByDescending(m => m.CreatedTime);
            SaleOrderDetailExport = search.Select(s => new SaleOrderDetailExport
            {
                ProductName = s.ProductName,
                Manufacturer = s.Product.Manufacturer,
                ManufacturingDate = s.Product.ManufacturingDate,
                ExpirationDate = s.Product.ExpirationDate,
                Price = s.Price,
                Num = s.Num,
                CreatedTime = s.CreatedTime,
            }).ToList();
            return SaleOrderDetailExport;
        }
        #endregion


    }
}
